package com.vsen.lpr.controller;


import com.vsen.lpr.common.base.BaseController;
import com.vsen.lpr.common.model.Response;
import com.vsen.lpr.pojo.dto.CommentDto;
import com.vsen.lpr.pojo.vo.CommentVo;
import com.vsen.lpr.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;
import java.util.List;

@Controller
@RequestMapping("/comment")
@Slf4j
public class CommentController extends BaseController {
    @Autowired
    private CommentService commentService;

    /**
     * 评论商品
     *
     * @return
     */
    @PostMapping("/comment")
    @ResponseBody
    Response productInfoList(@RequestBody @Validated CommentDto commentDto,BindingResult bindingResult) {
        checkParameters(bindingResult);
        return commentService.comment(commentDto);
    }

    /**
     * 商品评论列表
     *
     * @return
     */
    @PostMapping("/commentList")
    @ResponseBody
    Response<List<CommentVo>> commentList(@RequestBody CommentDto commentDto) {
        return commentService.commentList(commentDto);
    }


}
